<template>
  <view class="alpha">
    <view class="item"
         v-for="item of letter"
         :key='item'
         @touchstart.prevent='handletouchstart'
         @touchmove='handletouchmove'
         @touchend='handletouchend'
         @click='handleclick'
         :ref='item'
    >
      {{item}}
    </view>
  </view>
</template>

<script>
export default {
  name: 'CityAlpha',
  data () {
    return {
      touchStatus: false,
      startY: 0,
      timer: null
    }
  },
  props: {
    cities: Array
  },
  computed: {
    letter () {
      const letter = []
      for (let i=0;i<this.cities.length;i++) {
        letter.push(this.cities[i].first)
      }
      return letter
    }
  },
  methods: {
    handleclick (e) {
      console.log("=this.$refs['A'][0].offsetTop",this.$refs['A'])

      this.$emit('change', e.target.dataset.ref)
    },
    handletouchstart () {
      this.touchStatus = true
    },
    handletouchmove (e) {
      if (this.touchStatus) {
        // if (this.timer) {
        //   clearTimeout(this.timer)
        // }
        // this.timer = setTimeout(() => {
        // }, 16)
      }
    },
    handletouchend () {
      this.touchStatus = false
    }
  },
  updated () {
    // console.log("=this.$refs['A'][0].offsetTop",this.$refs['A'][0].offsetTop)
    // this.startY = this.$refs['A'][0].offsetTop
  }
}
</script>

<style lang="scss" scoped="">
.alpha{
  position: absolute;
  top:180rpx;
  right: 20rpx;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.item{
  text-align: center;
  line-height: 42rpx;
  color: #333;
}
</style>
